package scau.hotel.hotel_service.service.impl;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import scau.hotel.hotel_service.entity.PricingRule;
import scau.hotel.hotel_service.mapper.PricingRuleMapper;
import scau.hotel.hotel_service.service.PricingRuleService;
import scau.hotel.hotel_model.controller.RespBean;

import javax.annotation.Resource;
import java.util.List;

/**
 * (PricingRule)表服务实现类
 *
 * @author makejava
 * @since 2022-03-28 20:26:00
 */
@Service("pricingRuleService")
public class PricingRuleServiceImpl implements PricingRuleService {
    @Resource
    private PricingRuleMapper pricingRuleMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param pricingRuleId 主键
     * @return 实例对象
     */
    @Override
    public PricingRule queryById(Integer pricingRuleId) {
        return this.pricingRuleMapper.queryById(pricingRuleId);
    }

    /**
     * 分页查询
     *
     * @param pricingRule 筛选条件
     * @return 查询结果
     */
    @Override
    public List<PricingRule> queryAll(PricingRule pricingRule) {
        return this.pricingRuleMapper.queryAll(pricingRule);
    }

    /**
     * 分页查询
     *
     * @param pricingRule 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PricingRule> queryByPage(PricingRule pricingRule, PageRequest pageRequest) {
        long total = this.pricingRuleMapper.count(pricingRule);
        return new PageImpl<>(this.pricingRuleMapper.queryAllByLimit(pricingRule, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pricingRule 实例对象
     * @return 实例对象
     */
    @Override
    public RespBean insert(PricingRule pricingRule) {
        this.pricingRuleMapper.insert(pricingRule);
        return RespBean.success();
    }

    /**
     * 修改数据
     *
     * @param pricingRule 实例对象
     * @return 实例对象
     */
    @Override
    public RespBean update(PricingRule pricingRule) {
        this.pricingRuleMapper.update(pricingRule);
        return RespBean.success();
    }

    /**
     * 通过主键删除数据
     *
     * @param pricingRuleId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pricingRuleId) {
        return this.pricingRuleMapper.deleteById(pricingRuleId) > 0;
    }
}
